package com.fantasy.easy.biz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fantasy.easy.biz.domain.BizBase;
import com.fantasy.easy.biz.domain.vo.DictVO;
import com.fantasy.easy.biz.service.BizBaseService;
import com.fantasy.easy.core.SessionSubjectUtils;
import com.fantasy.easy.core.annotation.EasyPermissionAction;
import com.fantasy.easy.core.entity.SysUserEntity;
import org.apache.catalina.manager.util.SessionUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author sdehua-帅德华
 * @Email sdhstart@qq.com
 * @Date 2022/6/24 14:47
 * @Version 1.0
 **/
@RestController
@RequestMapping("base")
public class BizBaseController {

    @Resource
    BizBaseService bizBaseService;

    @GetMapping("info")
    public IPage<BizBase> getInfo(@RequestBody(required = false) BizBase bizBase, Page<BizBase> p){
        SysUserEntity user = SessionSubjectUtils.getUserEntity();
        if (!user.getName().equals("admin")){
            int id = bizBaseService.getIdByName(user.getName());
            BizBase base = new BizBase();
            base.setId(id);
            base.setUsername(user.getName());
            return bizBaseService.queryAll(base,p);
        }
        return bizBaseService.queryAll(bizBase,p);
    }

    @PostMapping("add")
    @EasyPermissionAction(auth="biz.base.add")
    public int addInfo(@RequestBody BizBase bizBase){
        return bizBaseService.addInfo(bizBase);
    }

    @DeleteMapping("delete")
    public int deleteInfo(@RequestBody Map<String,Integer> map){
        return bizBaseService.deleteInfo(map.get("userId"));
    }


}
